package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"zy16/Appconfig"
)

var DB *gorm.DB

func Init() {
	data := Appconfig.Config.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", data.User, data.Pass, data.Host, data.Port, data.Database)
	//dsn :=
	var err error
	DB, err = gorm.Open(mysql.Open(dsn))
	if err != nil {
		panic(err)
	} else {
		log.Println("连接成功")
	}
	DB.AutoMigrate(&Xinwen{})
}
